﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class UserCenter_user_Infor : System.Web.UI.Page
{
    BLL.Business.UserBLL userBLL = new BLL.Business.UserBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        { BindData(); }
        if (!object.Equals(Session["UserName"], null))
        { }
        else
        {
            Response.Write("<script>window.open('user_Login.aspx')</script>");
        }
    }

    public void BindData()
    {
        try
        {
            if (!object.Equals(Session["UserName"], null))
            {
                DataSet ds = new DataSet();
                ds = userBLL.SelectByName(Session["UserName"].ToString());
                if ((ds == null) ||
                   (ds.Tables.Count == 0) ||
                   (ds.Tables.Count == 1 && ds.Tables[0].Rows.Count == 0))
                { }
                else
                {
                    this.TextBox1.Text = ds.Tables[0].Rows[0]["User_Namestr"].ToString();
                    this.TextBox3.Text = ds.Tables[0].Rows[0]["User_Mailstr"].ToString();
                    this.TextBox4.Text = ds.Tables[0].Rows[0]["User_Addressstr"].ToString();
                    this.TextBox5.Text = ds.Tables[0].Rows[0]["User_Telephonestr"].ToString();
                    this.secproblem.Value = ds.Tables[0].Rows[0]["User_Questionstr"].ToString();
                    this.TextBox6.Text = ds.Tables[0].Rows[0]["User_Answerstr"].ToString();
                }
            }
            else
            {
                //Response.Redirect("user_login.aspx");
                Response.Write("<script>window.open('user_login.aspx')</script>");
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + ex.Message.ToString() + "')</script>");
        }
    }
    // 提交修改
    protected void update_Click(object sender, EventArgs e)
    {
        try
        {
            Model.User user = new Model.User();
            user.User_Namestr = this.TextBox1.Text.Trim().ToString();
            user.User_Mailstr = this.TextBox3.Text.Trim().ToString();
            user.User_Addressstr = this.TextBox4.Text.Trim().ToString();
            user.User_Telephonestr = this.TextBox5.Text.Trim().ToString();
            if (this.secproblem.Value != null && this.secproblem.SelectedIndex > 0 && this.TextBox6.Text.Trim() != null)
            {
                user.User_Questionstr = this.secproblem.Value;
                user.User_Answerstr = this.TextBox6.Text.Trim().ToString();
            }
            else
            {
                user.User_Questionstr = "";
                user.User_Answerstr = "";
            }
            if (userBLL.Update(user))
            { Response.Write("<script>alert('修改成功！')</script>"); }
            else
            { Response.Write("<script>alert('更改出现错误，请查证！')</script>"); }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + ex.Message.ToString() + "')</script>");
        }
    }
}
